package com.trace.pplos.parse.dao.dataobject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

public class MqmyInfo {
    private static final Logger logger = LoggerFactory.getLogger(MqmyInfo.class);

    private Integer id;

    private String massege;

    private String fromUser;

    private String userPhone;

    private String address;

    private String photoPath;

    private String synced;

    private String createdBy;

    private String voicePath;

    private String cjdw;

    private String filepath;

    private String lng;

    private String lat;

    private Date gmtCreate;

    private String gmtCreateUser;

    private Date gmtModified;

    private String gmtModifiedUser;

    private Integer status;

    public MqmyInfo(Integer id, String massege, String fromUser, String userPhone, String address, String photoPath, String synced, String createdBy, String voicePath, String cjdw, String filepath, String lng, String lat, Date gmtCreate, String gmtCreateUser, Date gmtModified, String gmtModifiedUser, Integer status) {
        this.id = id;
        this.massege = massege;
        this.fromUser = fromUser;
        this.userPhone = userPhone;
        this.address = address;
        this.photoPath = photoPath;
        this.synced = synced;
        this.createdBy = createdBy;
        this.voicePath = voicePath;
        this.cjdw = cjdw;
        this.filepath = filepath;
        this.lng = lng;
        this.lat = lat;
        this.gmtCreate = gmtCreate;
        this.gmtCreateUser = gmtCreateUser;
        this.gmtModified = gmtModified;
        this.gmtModifiedUser = gmtModifiedUser;
        this.status = status;
    }

    public MqmyInfo() {
        super();
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getMassege() {
        return massege;
    }

    public void setMassege(String massege) {
        this.massege = massege == null ? null : massege.trim();
    }

    public String getFromUser() {
        return fromUser;
    }

    public void setFromUser(String fromUser) {
        this.fromUser = fromUser == null ? null : fromUser.trim();
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone == null ? null : userPhone.trim();
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address == null ? null : address.trim();
    }

    public String getPhotoPath() {
        return photoPath;
    }

    public void setPhotoPath(String photoPath) {
        this.photoPath = photoPath == null ? null : photoPath.trim();
    }

    public String getSynced() {
        return synced;
    }

    public void setSynced(String synced) {
        this.synced = synced == null ? null : synced.trim();
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy == null ? null : createdBy.trim();
    }

    public String getVoicePath() {
        return voicePath;
    }

    public void setVoicePath(String voicePath) {
        this.voicePath = voicePath == null ? null : voicePath.trim();
    }

    public String getCjdw() {
        return cjdw;
    }

    public void setCjdw(String cjdw) {
        this.cjdw = cjdw == null ? null : cjdw.trim();
    }

    public String getFilepath() {
        return filepath;
    }

    public void setFilepath(String filepath) {
        this.filepath = filepath == null ? null : filepath.trim();
    }

    public String getLng() {
        return lng;
    }

    public void setLng(String lng) {
        this.lng = lng == null ? null : lng.trim();
    }

    public String getLat() {
        return lat;
    }

    public void setLat(String lat) {
        this.lat = lat == null ? null : lat.trim();
    }

    public Date getGmtCreate() {
        return gmtCreate;
    }

    public void setGmtCreate(Date gmtCreate) {
        this.gmtCreate = gmtCreate;
    }

    public String getGmtCreateUser() {
        return gmtCreateUser;
    }

    public void setGmtCreateUser(String gmtCreateUser) {
        this.gmtCreateUser = gmtCreateUser == null ? null : gmtCreateUser.trim();
    }

    public Date getGmtModified() {
        return gmtModified;
    }

    public void setGmtModified(Date gmtModified) {
        this.gmtModified = gmtModified;
    }

    public String getGmtModifiedUser() {
        return gmtModifiedUser;
    }

    public void setGmtModifiedUser(String gmtModifiedUser) {
        this.gmtModifiedUser = gmtModifiedUser == null ? null : gmtModifiedUser.trim();
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public static MqmyInfo toBean(String object){
        try{
            MqmyInfo info = new MqmyInfo();
            JSONObject record = JSON.parseObject(object);
            info.setSynced("0");
            info.setFromUser(record.getString("yjly"));
            info.setMassege(record.getString("yjnr"));
            info.setAddress(record.getString("address"));
            info.setUserPhone(record.getString("lxfs"));
            info.setLat(record.getString("latitude"));
            info.setLng(record.getString("longitude"));

            info.setGmtCreate(record.getDate("createdAt"));
            info.setGmtCreateUser(record.getString("createdBy"));
            //info.setGmtModified(record.getDate("modifiedAt"));
            info.setGmtModified(new Date());
            info.setGmtModifiedUser(record.getString("modifiedBy"));

            //音频路径
            String filePaths = "";
            JSONArray list = record.getJSONArray("voiceList");
            for (int i = 0; i < list.size(); i++) {
                JSONObject dataObj = list.getJSONObject(i);
                filePaths += dataObj.getString("path") +",";
            }
            info.setVoicePath(filePaths);

            //图片资料
            filePaths = "";
            list = record.getJSONArray("pictureList");
            for (int i = 0; i < list.size(); i++) {
                JSONObject dataObj = list.getJSONObject(i);
                filePaths += dataObj.getString("path") +",";
            }
            info.setPhotoPath(filePaths);
            return info;
        }catch (Exception e){
            logger.error(e.getMessage(), e);
        }
        return null;
    }
}